﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MINERP.BLL.Statistics;
using MINERP.MODEL.Statistics;

namespace MINERP.Statistics
{
    public partial class FrmSalesman : Form
    {
        FinanceBLL _bll = new FinanceBLL();

        
        private static FrmSalesman _instance = null;

        private FrmSalesman()
        {
            InitializeComponent();
        }
        public static FrmSalesman GetInstance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new FrmSalesman();
                }
                return _instance;
            }
        }

        private void FrmSalesman_Load(object sender, EventArgs e)
        {
            try
            {
                LinkGrid();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                string savePath = folderBrowserDialog1.SelectedPath + "\\业务员列表.xls";
                this.Cursor = Cursors.WaitCursor;
                gcSalesman.MainView.ExportToXls(savePath);
                this.Cursor = Cursors.Default;
                MessageBox.Show("已成功导出到:" + savePath, "成功导出", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void LinkGrid()
        {
            gcSalesman.DataSource = _bll.GetSalesmanInfoList();
        }

        private void tsbtnchongzhi_Click(object sender, EventArgs e)
        {
            Salesman_Info salesmanInfo = (Salesman_Info)gvSalesman.GetFocusedRow();
            if (salesmanInfo != null)
            {
                FrmSalesmanPay frm = FrmSalesmanPay.GetInstance(salesmanInfo);
                frm.WindowState = FormWindowState.Maximized;
                frm.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择要充值的业务员!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }

        private void gvSalesman_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {

        }

        private void FrmSalesman_FormClosed(object sender, FormClosedEventArgs e)
        {
            _instance = null;
        }

    }
}
